package mx.kolobok.noteeditor.ui.keymap;

import mx.kolobok.noteeditor.ui.MainForm;
import mx.kolobok.noteeditor.ui.keymap.actions.Actions;
import mx.kolobok.noteeditor.ui.list.NoteList;

import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map;

/**
 * User:  Nikita Belenkiy
 * Date: 29.05.11
 * Time: 4:04
 */
public class Keymap {
    private static final Keymap instance = new Keymap();

    private Map<Class,InputMap> inputMaps = new HashMap<Class, InputMap>();
    private Map<Class,ActionMap> actionMaps = new HashMap<Class, ActionMap>();

    private Keymap() {
        initInputMaps();
        initActionMaps();
    }

    private void initActionMaps() {

    }

    private void initInputMaps() {
        InputMap noteListInputMap = new InputMap();

        InputMap windowInputMap = new InputMap();
        windowInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), Actions.DELETE_NOTE_ACTION);
        windowInputMap.put(Actions.NEW_NOTE_KEYSTROKE, Actions.NEW_NOTE_ACTION);
        windowInputMap.put(Actions.NEW_NOTE_FROM_CLIPBOARD_KEYSTROKE, Actions.NEW_NOTE_FROM_CLIPBOARD_ACTION);
        windowInputMap.put(Actions.DELETE_KEYSTROKE, Actions.DELETE_NOTE_ACTION);
        windowInputMap.put(Actions.RENAME_KEYSTROKE, Actions.RENAME_NOTE_ACTION);
        windowInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK), Actions.RENAME_NOTE_ACTION);


        inputMaps.put(NoteList.class, noteListInputMap);
        inputMaps.put(MainForm.class, windowInputMap);

        noteListInputMap.setParent(windowInputMap);
    }


    public static Keymap getInstance() {
        return instance;
    }

    public  InputMap getInputMapForComponent(Class clazz) {
        return inputMaps.remove(clazz);
    }
    public  ActionMap getActionMap(Class clazz) {
        return null;
    }

}
